<style></style>
<!--  -->
<template>
  <div></div>
</template>

<script>
import Global from '@/config/global'
import Session from '@/core/session'
// import { sessionRouter } from '@/core/functions'
export default {
  data () {
    return {}
  },
  created () {
    const token = !this.$route.query.token ? null : this.$route.query.token
    // const token = null
    if (!token) {
      this.$msgbox({
        title: '提示',
        message: '请重新登录！',
        type: 'error',
        callback: () => {
          console.log('跳转')
        }
      })
      return
    }
    // 通过 token 获取用户信息并登录
    const loadingInstance = this.$loading({
      lock: true,
      text: '正在登录',
      spinner: 'el-icon-loading',
      background: 'rgba(0, 0, 0, 0.7)'
    })
    // 清除 storage 中的 session 数据
    // storage.clsSession()
    this.$post('/login?s=' + new Date().getTime(), { token }).then(
      (response) => {
        if (response) {
          Object.keys(localStorage).forEach(item => item.indexOf('langxInit') !== -1 ? localStorage.removeItem(item) : '')
          let callback = () => {
            let url = '/backend/user?' + Session.routerQueryString(response.jsessionid)
            window.location.href = url
          }
          this.$store.dispatch('userLogin', { response, callback: callback })
          if (response.loginUrl) {
            sessionStorage.setItem('sessionloginUrl', response.loginUrl)
          }
          loadingInstance.close()
        }
      },
      (error) => {
        this.$alert('请求登录失败，请联系管理员！', '提示', {
          confirmButtonText: '确定',
          type: 'error',
          callback: (action) => {
            window.location.href = Global.masterUrl
          }
        })
        console.error(error)
        loadingInstance.close()
      }
    )
  }
}
</script>
